package cn.itsource.hrm.rabbitmq.handler;

import cn.itsource.hrm.config.RabbitmqConfig;
import cn.itsource.hrm.util.SmsUtil;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class ReceiveHandler {
    //监听email队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receive_email(String msg, Message message, Channel channel) {
        String email = JSONObject.parseObject(msg).getString("email");
        if (StringUtils.isNotBlank(email)){
            System.out.println("email receive:"+msg);
            //@TODO
        }
    }

    //监听sms队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_SMS})
    public void receive_sms(String msg, Message message, Channel channel) {
        String phone = JSONObject.parseObject(msg).getString("phone");
        if (StringUtils.isNotBlank(phone)){
            System.out.println("sms receive:"+msg);
            SmsUtil.sendMsg(phone,"尊敬的用户您好！您已经在我们平台完成注册！祝你接下来体验愉悦！");
        }

    }
} 